﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;
using Gift.Model;

namespace WebSite.admin.system
{
    public partial class shop_config : BaseAdmin
    {
        // Fields
   

        // Methods
        private void Bind()
        {
            string sql = "select top 1 * from DB_Shopconfig where isnull(shopid,0)=" + base.AdminShopId;
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            this.shopname.Value = table.Rows[0]["shopname"].ToString();
            this.shopurl.Value = table.Rows[0]["shopurl"].ToString();
            this.shoptitle.Value = table.Rows[0]["shoptitle"].ToString();
            this.shopcontent.Value = table.Rows[0]["shopcontent"].ToString();
            this.shopkey.Value = table.Rows[0]["shopkey"].ToString();
            this.Label1.Text = table.Rows[0]["shopcountry"].ToString();
            this.Label2.Text = table.Rows[0]["shopprovince"].ToString();
            this.Label3.Text = table.Rows[0]["shopcity"].ToString();
            this.shopaddress.Value = table.Rows[0]["shopaddress"].ToString();
            this.shopqq.Value = table.Rows[0]["shopqq"].ToString();
            this.shopmsn.Value = table.Rows[0]["shopmsn"].ToString();
            this.shopaliwan.Value = table.Rows[0]["shopaliwan"].ToString();
            this.shopskype.Value = table.Rows[0]["shopskype"].ToString();
            this.shopyahoo.Value = table.Rows[0]["shopyahoo"].ToString();
            this.shopemail.Value = table.Rows[0]["shopemail"].ToString();
            this.shoptel.Value = table.Rows[0]["shoptel"].ToString();
            this.shopisweb.SelectedValue = table.Rows[0]["shopisweb"].ToString();
            this.shopwebmsg.Text = table.Rows[0]["shopwebmsg"].ToString();
            this.shoplogo.Text = table.Rows[0]["shoplogo"].ToString();
            this.shopmembermsg.Text = table.Rows[0]["shopmembermsg"].ToString();
            this.shopmsg.Text = table.Rows[0]["shopmsg"].ToString();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            upload upload = new upload();
            string str = upload.Up(this.file1, "../../uploadfile/banner/");
            base.Response.Write(upload.Resup[Convert.ToInt32(str)]);
            this.shoplogo.Text = upload.s;
        }

        public string getJSContent()
        {
            string str = " var city = new Array(";
            string str2 = "";
            string str3 = "";
            string sql = "select * from DB_Area where parentid=0";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                str = str + "'" + table.Rows[i][2].ToString().Trim() + "',";
                string str5 = "select * from DB_Area where parentid = " + table.Rows[i][0].ToString().Trim();
                DataTable table2 = new DataTable();
                table2 = SQLAccess.GreatDs(str5).Tables[0];
                object obj2 = str2;
                str2 = string.Concat(new object[] { obj2, " var prov", i, " = new Array(" });
                for (int j = 0; j < table2.Rows.Count; j++)
                {
                    str2 = str2 + "'" + table2.Rows[j][2].ToString().Trim() + "',";
                    string str6 = "select * from DB_Area where parentid = " + table2.Rows[j][0].ToString().Trim();
                    DataTable table3 = new DataTable();
                    table3 = SQLAccess.GreatDs(str6).Tables[0];
                    object obj3 = str3;
                    str3 = string.Concat(new object[] { obj3, " var place", i, "_", j, " = new Array(" });
                    for (int k = 0; k < table3.Rows.Count; k++)
                    {
                        str3 = str3 + "'" + table3.Rows[k][2].ToString().Trim() + "',";
                    }
                    if (str3.EndsWith(","))
                    {
                        str3 = str3.Substring(0, str3.Length - 1);
                    }
                    str3 = str3 + ");\n\r";
                }
                if (str2.EndsWith(","))
                {
                    str2 = str2.Substring(0, str2.Length - 1);
                }
                str2 = str2 + ");\n\r";
            }
            if (str.EndsWith(","))
            {
                str = str.Substring(0, str.Length - 1);
            }
            str = str + ");\n\r";
            return ("<script language='javascript'>\n\r" + str + str2 + str3 + "</script>");
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            string str = base.Request.Form["city"];
            string str2 = base.Request.Form["province"];
            string str3 = base.Request.Form["place"];
            if (str == "请选择")
            {
                str = "";
            }
            if (str2 == "请选择")
            {
                str2 = "";
            }
            if (str3 == "请选择")
            {
                str3 = "";
            }
            SQLAccess.DoSql("update DB_Shopconfig set shopname='" + re.replace(this.shopname.Value) + "',shopurl='" + re.replace(this.shopurl.Value) + "',shoptitle='" + re.replace(this.shoptitle.Value) + "',shopcontent='" + re.replace(this.shopcontent.Value) + "',shopkey='" + re.replace(this.shopkey.Value) + "',shopcountry='" + re.replace(str) + "',shopprovince='" + re.replace(str2) + "',shopcity='" + re.replace(str3) + "',shopaddress='" + re.replace(this.shopaddress.Value) + "',shopqq='" + re.replace(this.shopqq.Value) + "',shopmsn='" + re.replace(this.shopmsn.Value) + "',shopaliwan='" + re.replace(this.shopaliwan.Value) + "',shopskype='" + re.replace(this.shopskype.Value) + "',shopyahoo='" + re.replace(this.shopyahoo.Value) + "',shopemail='" + re.replace(this.shopemail.Value) + "',shoptel='" + re.replace(this.shoptel.Value) + "',shopisweb=" + re.replace(this.shopisweb.SelectedValue) + ",shopwebmsg='" + re.replace(this.shopwebmsg.Text) + "',shoplogo='" + re.replace(this.shoplogo.Text) + "',shopmembermsg='" + re.replace(this.shopmembermsg.Text) + "',shopmsg='" + re.replace(this.shopmsg.Text) + "' where isnull(shopid,0)=" + base.AdminShopId
            );
            base.Response.Write("<script language='javascript'>window.location.href='shop_config.aspx';</script>");
            base.Response.End();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
          
             base.Response.Write(this.getJSContent());
            if (!base.IsPostBack)
            {
                base.ValidateLoginRule(Gift.Model.ENUM.ERule.StoreConfiguration);
                this.Bind();
            }
           
        }

   
    }
}